<?php
	$auth = Zend_Auth::getInstance()->setStorage(new Zend_Auth_Storage_Session('user'));
	$slider = '';
	
	// Quảng cáo ở giữa kế bên search
	if(count($this->adv3) > 0) {
		$slider .= '<div class="slideshow" data-transition="crossfade" data-loop="true" data-skip="false">';
		$slider .= '<ul class="carousel">';
		
		While (list($key, $val) = each($this->adv3)) {
			if ($auth->hasIdentity()) {
				$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point3 .')';
			} else {
				$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
			}

			$slider .= '<li class="slide">';
			$slider .= $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
			$slider .= '</li>';
		}

		$slider .= '</ul>';
		$slider .= "</div>";
		$slider .= '<script type="text/javascript">';
		$slider .= '$(".slideshow").slides({hoverPause: true, speed: 600, autostop: false, auto: 4000});';
		$slider .= '</script>';
	}
	
	$layout = $this->cmsSearch('slider', '36%', $slider); 
	echo $layout;
	$layout = $this->cmsSubmenu(); 
	echo $layout;
	
	$listTinTuc = $this->itemsListTinTuc;
?>

<div id="wrapcontent">
	<?php
		// Quảng cáo ở bên trái
		if(count($this->adv2) > 0) {
			echo "<div id='floating_banner_left'>";
			
			While (list($key, $val) = each($this->adv2)) {
				if ($auth->hasIdentity()) {
					$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point2 .')';
				} else {
					$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
				}
					
				echo $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
			}
			
			echo "</div>";
		} 
	?>
	<div id="sidebar1">
		<?php
			$img = '<img src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/icon_hot.gif") . '" />';
			$block = $this->cmsBlock('Phòng trọ', $img, $this->itemsHotPtrTinTro); 
			echo $block;
			
			// Logo ở bên trái
			if(count($this->adv5) > 0) {
				echo "<div>";
					
				While (list($key, $val) = each($this->adv5)) {
					if ($auth->hasIdentity()) {
						$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point5 .')';
					} else {
						$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
					}
			
					echo $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
				}
					
				echo "</div>";
			}
		?>
		<!-- Begin Block hỗ trợ trực tuyến -->
		<?php 
			$block = $this->cmsBlock('Hỗ trợ trực tuyến', '', $this->thong_tin_cty, 3); 
			echo $block;
		?>
		<!-- End Block hỗ trợ trực tuyến -->
		<!-- Begin Block thống kê truy cập -->
		<?php 
			$block = $this->cmsBlock('Thống kê truy cập', '', 'info', 4); 
			echo $block;
		?>
		<!-- End Block thống kê truy cập -->
		<br class="clear" />
	</div>
	<?php
		// Quảng cáo ở bên phải
		if(count($this->adv4) > 0) {
			echo "<div id='floating_banner_right'>";
		
			While (list($key, $val) = each($this->adv4)) {
				if ($auth->hasIdentity()) {
					$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point4 .')';
				} else {
					$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
				}
					
				echo $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
			}
		
			echo "</div>";
		}
	?>
	<div id="sidebar2">
		<div class="block">
			<div class="title">
				<span>Mạng xã hội</span>
			</div>
			<div class="content">
				<div class="follow">
					<div class="addthis_toolbox addthis_32x32_style addthis_vertical_style">
						<a class="addthis_button_facebook_follow" addthis:userid="kenhnhatro.vn"></a>
						<a class="addthis_button_twitter_follow" addthis:userid="kenh_nhatro"></a>
					</div>
				</div>
			</div>
			<br class="clear" />
		</div>
		<?php
			$img = '<img src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/icon_new.gif") . '" />';
			$block = $this->cmsBlock('Tin rao mới', $img, $this->itemsNewPtrTinTro); 
			echo $block;
			$img = '<img class="icon" src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/highlights.png") . '" />';
			$block = $this->cmsBlock('Tin tức nổi bật', $img, $this->itemsHotTinTuc, 2);
			echo $block;
			
			// Logo ở bên phải
			if(count($this->adv6) > 0) {
				echo "<div>";
					
				While (list($key, $val) = each($this->adv6)) {
					if ($auth->hasIdentity()) {
						$clickHandler = 'clickAdv(true, ' . $auth->getIdentity()->id . ', ' . $val->getPage_id() . ', ' . $val->getVi_tri() . ', "' . $val->getUrl() . '", '. $this->point6 .')';
					} else {
						$clickHandler = 'clickAdv(false, 0, 0, 0, "' . $val->getUrl() . '", 0)';
					}
			
					echo $this->cmsAdvertisement($this->baseUrl(ADV_IMAGES_PATH . $val->getImage_url()), false, $clickHandler);
				}
					
				echo "</div>";
			}
		?>
	</div>
	<div id="primary">
		<div class="block">
			<div class="title">
				<div class="icon-arrow"></div>
				<span>Tin tức nhà trọ</span>
			</div>
			<div class="content">
				<?php
					foreach ($listTinTuc as $val) {
						$id_tin_tuc	= $val->id;
						$tieu_de 	= $val->tieu_de;
						$hinh_anh 	= $this->baseUrl(NEWS_IMAGES_PATH . NEWS_IMAGE_PREFIX1 . '/' . NEWS_IMAGE_PREFIX1 . $val->hinh_anh);
						$luot_xem 	= $val->luot_xem;
						$ngay_dang 	= $val->ngay_tao;
						$gioi_thieu	= $val->gioi_thieu;
						$html = '<div class="item">';
						$html .= '<div class="metadata">';
						$html .= '<img src="' . $hinh_anh . '" alt="' . $val->tieu_de . '"  width="94px" height="94px" onerror="this.onerror=null; this.src=\'' . $this->baseUrl(NEWS_IMAGES_PATH . 'error/94_94_news_default.png') . '\';" />';
						$html .= '</div>';
						$html .= '<a title="' . $tieu_de . '" rel="bookmark" href="' . $this->baseUrl("tintuc/view/id/" . $id_tin_tuc) . '">' . Zendhlt_Encode::truncateString_($tieu_de, 48) . '</a>';
						$html .= '<p class="date">' . $ngay_dang . '</p>';
						$html .= '<div class="info">';
						$html .= $gioi_thieu;
						$html .= '</div>';
						$html .= '<div class="clear"></div></div>';
						echo $html;
					};
				?>
				<?php if ($this->totalItem > 10) {?>
					<div class="pagenavi">
						<div class="pagination">
						<?php
							$currentUrl = $this->baseUrl($this->currentController . '/index');
							echo $this->paginationControl($this->panigator, 'Sliding', 'pagination.phtml', array('currentUrl' => $currentUrl));
						?>
						</div>
						<br class="clear" />
					</div>
				<?php } ?>
			</div>
			<br class="clear" />
		</div>
	</div>
   	<div class="clear"></div>
</div>